
#ifndef	PROJECT_H_INCLUDED
#define	PROJECT_H_INCLUDED

// standard C headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h>

// OpenSSL headers
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/sha.h>
#include <openssl/des.h>
#include <openssl/aes.h>

// C++ STL containers used by the project
#include <list>
#include <map>
#include <set>

// macros for manipulating C++ STL containers
#define	iterator(type,container,index)\
for (type::iterator index = (container).begin(), index##_end = (container).end(); index != index##_end; ++index)

// message structure used by low level message sending
// and receiving functions.
typedef struct MSG {
	long size;
	void *data;
} MSG;

// message send/recv code
int
write_msg(BIO *cbio, MSG *msg);
int
read_msg(BIO *cbio, MSG *msg);
int
send_recv(MSG *msg, MSG *res);

// macros for creating and initializing messages
#define	MSG_FREE(M)	free((M)->data)
#define	MSG_BODY(M, offset, type)	((type *)((char *)((M)->data)+(offset)))
#define MSG_TYPE(M)	(*(int *)((M)->data))

// message IDs
#define	MSG_ECHO_TEST					255
#define	MSG_ECHO_TEST_REPL				254
#define	MSG_ECHO_TEST_RSA				253
#define	MSG_GET_CTF_PUBLIC_KEY			1
#define	MSG_GET_CTF_PUBLIC_KEY_REPL		2
#define	MSG_BLND_SIGN_VOTING_KEY		3
#define	MSG_BLND_SIGN_VOTING_KEY_REPL	4
#define	MSG_VOTING_KEY					5
#define	MSG_VOTING_KEY_REPL				6
#define	MSG_VOTE						7
#define	MSG_DECRYPT_VOTE				8
#define	MSG_ADMIN_REG					9
#define	MSG_ADMIN_TALLY_KEYS			10
#define	MSG_ADMIN_VOTE					11
#define	MSG_ADMIN_TALLY					12
#define	MSG_ADMIN_DONE					13


RSA *get_ctf_public_key(MSG *msg);
MSG *
build_ctf_public_key_MSG(RSA *key);
void
alloc_msg(int size, MSG *msg);


#endif
